package com.example.administrator.qimo3no74.my;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.qimo3no74.R;

import java.util.List;

public class ToolIconAdapter extends RecyclerView.Adapter<ToolIconAdapter.ViewHolder> {

    private List<ToolIcon> toolIcons;

    static  class ViewHolder extends RecyclerView.ViewHolder{
        ImageView toolImg;
        TextView toolName;

        public ViewHolder(View itemView, final Context context){
            super(itemView);
            this.toolImg = itemView.findViewById(R.id.toolImageViewIcon);
            this.toolName = itemView.findViewById(R.id.toolTextViewName);

            toolImg.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(context,""+toolName.getText(),Toast.LENGTH_SHORT).show();
                }
            });
            toolName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(context,""+toolName.getText().toString(),Toast.LENGTH_SHORT).show();
                }
            });
        }
    }

    public ToolIconAdapter(List<ToolIcon> toolIcons){
        this.toolIcons = toolIcons;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.tool_icon_item,viewGroup,false);
        ViewHolder holder = new ViewHolder(view,viewGroup.getContext());
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        ToolIcon toolIcon = toolIcons.get(i);
        viewHolder.toolImg.setImageResource(toolIcon.getToolImgId());
        viewHolder.toolName.setText(toolIcon.getToolName());
    }

    @Override
    public int getItemCount() {
        return toolIcons.size();
    }

}
